package com.youi.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.youi.common.Common;
import com.youi.common.DelStatus;
import com.youi.dao.GroupleaderbankDao;
import com.youi.entity.Groupleader;
import com.youi.entity.Groupleaderbank;
import com.youi.entity.Leaderstore;
import com.youi.service.GroupleaderService;
import com.youi.service.GroupleaderbankService;
import com.youi.service.LeaderstoreService;

@Service
public class GroupleaderbankServiceImpl extends BaseServiceImpl<Groupleaderbank> implements GroupleaderbankService{
		
		private GroupleaderbankDao groupleaderbankDao;
		
		@Autowired
		private LeaderstoreService leaderstoreService;
		@Autowired
		private GroupleaderService groupleaderService;
		@Autowired
		public void setfaultRecordDao(GroupleaderbankDao groupleaderbankDao){
			this.groupleaderbankDao=groupleaderbankDao;
			super.setBaseDAO(groupleaderbankDao);
		}

		@Override
		public void getGroupleaderbank(List<Groupleaderbank> groupleaderbankList) {
			// TODO Auto-generated method stub
			if (groupleaderbankList!=null&&groupleaderbankList.size()>0) {
				for (Groupleaderbank groupleaderbank : groupleaderbankList) {
					getGroupleaderbank(groupleaderbank);
				}
			}
		}

		@Override
		public void getGroupleaderbank(Groupleaderbank groupleaderbank) {
			// TODO Auto-generated method stub
			if (groupleaderbank!=null) {
				Map<String, Object> prams=new HashMap<String, Object>();
				prams.put(Common.DELSTATUS, DelStatus.NODEL);
				prams.put("leaderId", groupleaderbank.getLeaderId());
				Leaderstore leaderstore=leaderstoreService.getByParam(prams);
				if (leaderstore!=null) {
					groupleaderbank.setLeaderstore(leaderstore);
				}
				Groupleader groupleader=groupleaderService.get(groupleaderbank.getLeaderId());
				if (groupleader!=null) {
					groupleaderbank.setWechatName(groupleader.getName());
				}
			}
		}

		@Override
		public List<Long> getLeaderId(String pms) {
			// TODO Auto-generated method stub
			if (pms!=null&&pms.trim().length()>0) {
				List<Long> leaderIdList=new ArrayList<Long>();
				Map<String, Object> prams=new HashMap<String, Object>();
				prams.put(Common.DELSTATUS, DelStatus.NODEL);
				Map<String, Object> searchParams=new HashMap<String, Object>();
				searchParams.put("phone", pms);
				searchParams.put("authStore", pms);
				List<Leaderstore> LeaderstoreList=leaderstoreService.getByParams(prams, searchParams, null);
				if (LeaderstoreList!=null&&LeaderstoreList.size()>0) {
					for (Leaderstore leaderstore : LeaderstoreList) {
						leaderIdList.add(leaderstore.getLeaderId());
					}
					return leaderIdList;
				}
			}
			return null;			
		}
}